import 'package:backend.core/core/domain/entities/api/google_play/api_google_play_one_time_purchased_item.dart';
import 'package:backend.core/core/domain/entities/google_play/google_play_one_time_purchased_item_info.dart';
import 'package:backend.core/core/domain/entities/google_play/google_play_one_time_purchased_item_transaction.dart';
import 'package:backend.purchases/domain/helpers/api/google_play/create_api_google_play_one_time_purchased_item_transaction_from_internal_one.dart';
import 'package:backend.purchases/domain/helpers/api/google_play/create_api_google_play_purchased_item_acknowledgement_status_from_internal_one.dart';

abstract class CreateApiGooglePlayOneTimePurchasedItemFromInternalOne {
  ApiGooglePlayOneTimePurchasedItem call({
    required GooglePlayOneTimePurchasedItemInfo oneTimePurchasedItemInfo,
    required GooglePlayOneTimePurchasedItemTransaction oneTimePurchasedItemTransaction,
  });
}

class CreateApiGooglePlayOneTimePurchasedItemFromInternalOneImpl
    implements CreateApiGooglePlayOneTimePurchasedItemFromInternalOne {
  const CreateApiGooglePlayOneTimePurchasedItemFromInternalOneImpl({
    required CreateApiGooglePlayOneTimePurchasedItemTransactionFromInternalOne
        createApiGooglePlayOneTimePurchasedItemTransactionFromInternalOne,
    required CreateApiGooglePlayPurchasedItemAcknowledgementStatusFromInternalOne
        createApiGooglePlayPurchasedItemAcknowledgementStatusFromInternalOne,
  })  : _createApiGooglePlayOneTimePurchasedItemTransactionFromInternalOne =
            createApiGooglePlayOneTimePurchasedItemTransactionFromInternalOne,
        _createApiGooglePlayPurchasedItemAcknowledgementStatusFromInternalOne =
            createApiGooglePlayPurchasedItemAcknowledgementStatusFromInternalOne;

  final CreateApiGooglePlayOneTimePurchasedItemTransactionFromInternalOne
      _createApiGooglePlayOneTimePurchasedItemTransactionFromInternalOne;
  final CreateApiGooglePlayPurchasedItemAcknowledgementStatusFromInternalOne
      _createApiGooglePlayPurchasedItemAcknowledgementStatusFromInternalOne;

  @override
  ApiGooglePlayOneTimePurchasedItem call({
    required GooglePlayOneTimePurchasedItemInfo oneTimePurchasedItemInfo,
    required GooglePlayOneTimePurchasedItemTransaction oneTimePurchasedItemTransaction,
  }) {
    final apiTransaction = _createApiGooglePlayOneTimePurchasedItemTransactionFromInternalOne(
      transaction: oneTimePurchasedItemTransaction,
    );

    final apiAcknowledgementStatus =
        _createApiGooglePlayPurchasedItemAcknowledgementStatusFromInternalOne(
      acknowledgementStatus: oneTimePurchasedItemInfo.acknowledgementStatus,
    );

    return ApiGooglePlayOneTimePurchasedItem(
      purchaseItemSku: oneTimePurchasedItemInfo.purchaseItemSku,
      purchaseToken: oneTimePurchasedItemInfo.purchaseToken,
      test: oneTimePurchasedItemInfo.test,
      acknowledgementStatus: apiAcknowledgementStatus,
      revoked: apiTransaction.revocationInfo != null,
      transaction: apiTransaction,
    );
  }
}
